<script setup lang="ts">
import useUserStore from "../../store/userStore";
import { getAllHistoryPaperAPI } from "../../api/paper.ts";
import { ref } from "vue";
import { HistoryPaper } from "../../index";

const userStore = useUserStore();

const userID = userStore.userID;

const papers = ref<HistoryPaper[]>([]);

const getData = () => {
  getAllHistoryPaperAPI(userID as number)
    .then((response) => {
      if (response.status !== 200) {
        throw new Error("网络错误");
      }
      return response.data;
    })
    .then((result) => {
      papers.value = result.data;
    });
};

getData();
</script>

<template>
  <div class="m-5">
    <el-card class="my-4" v-for="paper in papers" :key="paper.id">
      <el-row>
        <el-col :span="22">
          <el-link :href="`/exam_history/${paper.id}`"
            >{{ paper.title }}
          </el-link>
        </el-col>
        <el-col :span="2">
          <el-link :href="`/exam_history_algorithm/${paper.id}`"
            >查看算法计算过程</el-link
          >
        </el-col>
      </el-row>
    </el-card>
  </div>
</template>

<style scoped></style>
